﻿using System;

delegate void NotifyCalculation(int x, int y, int result);

class Calculator
{
    NotifyCalculation calcListener;

    public void AddLsitener(NotifyCalculation listener)
    {
        calcListener += listener;
    }

    public void RemoveLsitener(NotifyCalculation listener)
    {
        calcListener -= listener;
    }

    public int CalculateProduct(int num1, int num2)
    {
        int result = num1 * num2;
        calcListener(num1, num2, result);

        return result;
    }
}

class CalculationListener
{
    private string idString;

    public CalculationListener(string id)
    {
        idString = id;
    }

    public void CalculationPrinter(int x , int y, int result)
    {
        Console.WriteLine("{0}: Notfication:{1} * {2} = {3}", idString, x, y, result);
    }
}

class AlternateListener
{
    public static void CalculationCallback(int x, int y, int result)
    {
        Console.WriteLine("Callback: {0} * {1} = {2}", x, y, result);
    }
}

class Program
{
    static void Main(string[] args)
    {
        Calculator calc = new Calculator();

        calc.AddLsitener(new CalculationListener("list1").CalculationPrinter);
        calc.AddLsitener(new CalculationListener("list2").CalculationPrinter);
        calc.AddLsitener(AlternateListener.CalculationCallback);

        calc.CalculateProduct(29, 32);

        calc.RemoveLsitener(AlternateListener.CalculationCallback);

        calc.CalculateProduct(14, 32);

        Console.WriteLine("press enter....");



    }
}